<?php 
/**
 * @Title: enclosing_method
 * @Description: 
 * @return: return_type
 * @author: yulong.wang
 * @date: 2015-1-15下午7:28:37
*/
use common\models\SysAdminUser;
use common\models\AfterSalesDest;
use common\models\AfterSalesDesSite;
use common\models\BaseAdminDes;
$this->title = '接收地市站点分配';
$this->params ['breadcrumbs'] [] = $this->title;
?>
<style>
.form-group{
	margin: 30px 0 30px 0;
}
.form-group span{
	font-size: 14px;
	border-color: #3c763d;
	box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
	background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
    color: #555;
    font-size: 14px;
    height: 34px;
    line-height: 1.42857;
    padding: 6px 12px;
    transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
}
input[type="checkbox"]{
	margin: 0;
	vertical-align: middle;
}
</style>
<div>
    <h3><?php echo $this->title?></h3>
    <form action="/sys-admin-user/assign-site" method="POST">
    <div class="form-group">
    <label class="control-label">管理员：</label>
    <span><?=SysAdminUser::getAdminUserNameById(f_get('admin_user_id'))?></span>
    <input type='hidden' name='admin_user_id' value='<?=f_get('admin_user_id')?>'>
    </div>
    <?php if (!empty($des_all)) {?>
    <div class="form-group">
		<label class="control-label">地市：</label>
		<table class="table table-bordered">
		<tbody>
		<?php foreach($des_all as $province_id => $sites){ ?>
			<tr>
				<td align="center"><input type="checkbox" class="province_id" data-id="<?= $province_id ?>">&nbsp;<b><?= \common\models\BaseRegion::getRegionName($province_id) ?></b></td>
				<td id="province_<?= $province_id ?>">
					<?php
					foreach ($sites as $key => $value) {
						if(BaseAdminDes::check(f_get('admin_user_id'), $key)){
					?>
					<input type='checkbox' name='des_id[]' value='<?= $key ?>' class="des_id" checked="checked" >&nbsp;<?= $value ?>&nbsp;&nbsp;&nbsp;
					<?php }else{?>
					<input type='checkbox' name='des_id[]' value='<?= $key ?>' class="des_id">&nbsp;<?= $value ?>&nbsp;&nbsp;&nbsp;
					<?php }} ?>
				</td>
			</tr>
		<?php } ?>
		</tbody>
		</table>
    </div>
    <?php } ?>
    <br/>
	<br/>
	<input type="button" value="全选" class="btn btn-success" id="choseAll"/>&nbsp;&nbsp;&nbsp;
	<input type="button" value="全不选" class="btn btn-success" id="delAll"/>&nbsp;&nbsp;&nbsp;
	<input type="button" value="反选" class="btn btn-success" id="fanAll"/>
	<br/>
	<br/>
    <div class="form-group">
	   <button type="submit" name='save' class="btn btn-success">提交</button>&nbsp;&nbsp;&nbsp;
	   <a href="/sys-admin-user/view?id=<?=f_get('admin_user_id')?>"><input type="button" class="btn btn-primary" value="返回上一页"></a>
	</div>
	</form>
</div>
<script>
//citys[0][]
//全部选择
	 $("#choseAll").click(function(){
		  $("input[name='des_id[]']").each(function(){
			  this.checked = true;
		  });
		 $(".province_id").each(function(){
			 this.checked = true;
		 });
	 });
	//取消选择
	 $("#delAll").click(function(){
		  $("input[name='des_id[]']").each(function(){
			  this.checked = false;
		  });
		 $(".province_id").each(function(){
			 this.checked = false;
		 });
	 });
	 $("#fanAll").click(function(){
		  $("input[name='des_id[]']").each(function(){
			  if(this.checked == false){
				  this.checked = true;
			  }else{
				  this.checked = false;
			  }
		  });
	 });

	$(".province_id").click(function(){
		var self = $(this);
		var province_id = self.attr("data-id");
		if(self.prop("checked")){
			$("#province_" + province_id).find("input[name='des_id[]']").each(function(){
				this.checked = true;
			});
		}else{
			$("#province_" + province_id).find("input[name='des_id[]']").each(function(){
				this.checked = false;
			});
		}
	});
</script>